<?php
/**
 * Created by PhpStorm.
 * User: jiang
 * Date: 2019/5/30
 * Time: 15:06
 */

namespace app\admin\controller;
use app\admin\model\OrderModel;
use think\Request;
use think\Session;


class Orders extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->order = new OrderModel();
    }
    public function index(){//订单列表的显示
        $list = $this->order->orderlist();//dump($list);
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('orders/index');
    }
    public function add(){//添加订单
        if(request()->isAjax())
        {
            $res = $this->order->add();
            if($res)
            {
                return ['code'=>'1','message'=>'添加成功'];
            }else{
                return ['code'=>'0','message'=>'添加失败'];
            }
        }
        return view('orders/add');
    }
    public function update(){//订单信息的修改
        if(request()->isAjax())
        {
           //dump($id);die;
            $res = $this->order->orderupdate();
           // dump($res);die;
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $res = $this->order->getOneId($id);
        $this->assign('data',$res);
        return view('update');
    }
    public function del(){//删除订单信息
        $res = $this->order->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
    public function dell(){//批量删除
        $res = $this->order->dell();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
}